package py.edu.ucom.cadira.net.serializables;

import org.jdom.Document;
import org.jdom.Element;

import py.edu.ucom.cadira.logic.Mesa;
import py.edu.ucom.cadira.net.XMLSerializable;

public class CreateResponse implements XMLSerializable {
	private Mesa mesa;
	private boolean status;
    //private String type = "pruebaXML";

	/**
     * @return Returns the mesa.
     */
    public Mesa getMesa() {
        return mesa;
    }
    /**
     * @param mesa The mesa to set.
     */
    public void setMesa(Mesa mesa) {
        this.mesa = mesa;
    }
    /**
     * @return Returns the type.
     */
/*    public String getType() {
        return type;
    }
    /**
     * @param type The type to set.
     */
/*    public void setType(String type) {
        this.type = type;
    }
    */
    public CreateResponse() {
		this.mesa = new Mesa();
		this.status = true;
	}
	public boolean isStatus() {
		return status;
	}
	public void setStatus(boolean status) {
		this.status = status;
	}
	public void fromXML(Document xml) {
		
		Element root = xml.getRootElement();
		Element createTableNode = root.getChild("createTable");
		Element statusNode = createTableNode.getChild("status");
		statusNode.setText("true");
        mesa.setStatus(Boolean.parseBoolean(statusNode.getValue()));
		Element tableNode = createTableNode.getChild("table");
		mesa.setMesaId(Integer.parseInt(tableNode.getAttributeValue("id")));
	}

	public void toXML(Element root) {
		
		Element createTableNode = new Element("createTable");
		Element statusNode = new Element("status");
		
		statusNode.addContent(Boolean.toString(mesa.isStatus()));
		createTableNode.addContent(statusNode);

		Element tableNode = new Element("table");
		tableNode.setAttribute("id",mesa.getMesaId().toString());
        /********************************/
		
		createTableNode.addContent(tableNode);
		root.addContent(createTableNode);
	}
    @Override
    public boolean equals(Object obj) {
        if(!(obj instanceof CreateResponse)){ 
            return false;
        }
        CreateResponse otherObj = (CreateResponse)obj;
        if (otherObj.getMesa().equals(getMesa())) {
            return true;
        }
        
        return false;
    }
}
